package com.note.mq.service.impl;

import com.note.mq.entity.MsgData;
import com.note.mq.service.MqSendMsgI;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class RabbitMqSendMsgImpl implements MqSendMsgI {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public void sendMsg(MsgData msgData) {
        if (msgData == null || msgData.getData() == null) {
            throw new RuntimeException("发送的内容不能为null");
        }

        if (StringUtils.isBlank(msgData.getQueueName())) {
            throw new RuntimeException("指定的队列名为空");
        }

        if (StringUtils.isBlank(msgData.getExchangeName())) {
            throw new RuntimeException("指定的交互机为空");
        }

        rabbitTemplate.convertAndSend(msgData.getExchangeName(), "", msgData.getData());


    }
}
